import java.util.*;


public class Solution {
    /**
     *
     * @param x int整型 
     * @return int整型
     */
    public int sqrt (int x) {
        // write code here
        int before=1;
        int after=x;
        int mid=1;
        if(x<=0){
            return 0;
        }
        while(before<=after){
            mid=before+(after-before)/2;
            if(before<=after&&((mid+1)*(mid+1)>x)&&(mid*mid<=x)){
                return mid;
            }
            if(before<=after&&mid*mid<x){
                before=mid+1;
            }
            else {
                after=mid-1;
            }
        }
        return 0;
    }
}